-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
42 lines (31 loc) · 782 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
void ordenar_desc(int v[], int tam);
int main(){
int n, q, i;
while(scanf("%d %d", &n, &q) != EOF){
int notas[n], pos[q];
for(i = 0; i < n; i++)
scanf("%d", ¬as[i]);
for(i = 0; i < q; i++)
scanf("%d", &pos[i]);
ordenar_desc(notas, n);
for(i = 0; i < q; i++)
printf("%d\n", notas[pos[i] - 1]);
}
return 0;
}
// Bubble sort
void ordenar_desc(int v[], int tam){
int i, temp, trocou;
do{
trocou = 0;
for(i = 0; i < tam - 1; i++){
if(v[i] < v[i + 1]){
temp = v[i];
v[i] = v[i + 1];
v[i + 1] = temp;
trocou = 1;
}
}
}while(trocou);
}